<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"             
                template="../../template/tagedu.xhtml">


    <ui:define name="title">
        <title><h:outputText value="TAG - Cadastrar Plano"/></title>
    </ui:define>
    <ui:define name="content">
        <link rel="Stylesheet" type="text/css" href="../../resources/css/main.css"></link>
        <link rel="Stylesheet" type="text/css" href="../../resources/css/plans.css"></link>
        <h:outputText styleClass="planName" value="Cadastro de Planos"/>
        <f:event type="preRenderComponent" listener="#{createOrganizationPlan.initPlan()}"/>
        <h:form styleClass="planOpt">
            <table width="950" border="0" cellpadding="0" cellspacing="0">
                <tr>
                    <td valign="top" style="">
                        <h:outputLabel styleClass="planOptLabel" for="yearsList" value="Ano*: "/>
                        <h:selectOneMenu id="yearsList" styleClass="planOptSOM" value="#{createOrganizationPlan.plan.planYear}" required="true" requiredMessage="Campo Obrigatório" style="">
                            <f:selectItems value="#{createOrganizationPlan.yearList}"/>
                        </h:selectOneMenu>
                        <h:message for="yearsList" styleClass="message"/>
                    </td>
                    <td valign="top" style="">
                        <h:outputLabel styleClass="planOptLabel" for="seasonList" value="Período*: "/>
                        <h:selectOneMenu id="seasonList" styleClass="planOptSOM" value="#{createOrganizationPlan.seasonID}" required="true" requiredMessage="Campo Obrigatório">
                            <f:selectItems value="#{createOrganizationPlan.seasonList}"/>
                        </h:selectOneMenu>
                        <h:message for="seasonList" styleClass="message"/>
                    </td>
                    <td valign="top" style="">
                        <h:outputLabel styleClass="planOptLabel" for="organization" value="Organização*: "/>
                        <h:selectOneMenu id="organization" styleClass="planOptSOM" value="#{createOrganizationPlan.organizationID}" required="true" requiredMessage="Campo Obrigatório">
                            <f:selectItems value="#{createOrganizationPlan.organizationList}"/>
                        </h:selectOneMenu>
                        <h:message for="organization" styleClass="message"/>
                    </td>
                    <td valign="top" style="">
                        <h:outputLabel styleClass="planOptLabel" for="discipline" value="Disciplina*: "/>
                        <h:selectOneMenu id="discipline" styleClass="planOptSOM" value="#{createOrganizationPlan.disciplineID}" required="true" requiredMessage="Campo Obrigatório">
                            <f:selectItems value="#{createOrganizationPlan.disciplineList}"/>
                        </h:selectOneMenu>
                        <h:message for="discipline" styleClass="message"/>
                    </td>
                    <td valign="top" style="">
                        <h:commandButton value="Criar" onclick="infoModal.show()">
                            <f:ajax execute="@form" render="@form :infoForm" listener="#{createOrganizationPlan.create()}"/>
                        </h:commandButton>
                    </td>
                </tr>
            </table>
        </h:form>
    </ui:define>

    <ui:define name="modals">
        <p:dialog closable="false" modal="true" header="Atenção" position="center" widgetVar="infoModal" resizable="false">
            <h:form id="infoForm">
                <table width="100%">
                    <tbody>
                        <tr>
                            <td align="center" width="50%">
                                <h:outputText rendered="#{createOrganizationPlan.success}" value="Cadastro realizado com sucesso!"/>
                                <br/>
                                <p:commandButton immediate="true" rendered="#{createOrganizationPlan.success}" value="OK" action="#{createOrganizationPlan.redirectNewRegister()}"/>
                                <h:outputText rendered="#{!createOrganizationPlan.success}" value="Por favor, corrija os erros encontrados!"/>
                                <br/>
                                <p:commandButton immediate="true" rendered="#{!createOrganizationPlan.success}" value="OK" onclick="infoModal.hide();"/>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </h:form>
        </p:dialog>
    </ui:define>
</ui:composition>